//
//  WKCommentViewController.m
//  WKDemo
//
//  Created by apple on 14-8-10.
//  Copyright (c) 2014年 com.app. All rights reserved.
//

#import "WKCommentViewController.h"
#import "WKVideoHttpTool.h"
#import "WKVideoParam.h"
#import "WKVideoModelFrame.h"
#import "WKVidelModel.h"
#import "WKVideoResult.h"
#import "WKCustomTableViewCell.h"
#import "WKCommentCell.h"

@interface WKCommentViewController ()
@property (nonatomic,strong)NSMutableArray *datas;
@end

@implementation WKCommentViewController
- (NSMutableArray *)datas
{
    if (_datas == nil) {
        _datas = [NSMutableArray array];
    }
    return _datas;
}
- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
   
    self.title = @"评论";
    WKVideoParam *param = [[WKVideoParam alloc] init];
    param.id = self.videoF.videoModel.id;
    [WKVideoHttpTool getCommentDataListWithParam:param success:^(WKVideoResult *result) {
        self.datas = [NSMutableArray arrayWithArray:result.homeDatas];
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        WKLog(@"%@",error);
    }];

}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return 2;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }else{
    return self.datas.count;
    }
}

//-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
//{
//    WKCustomTableViewCell *custom = [[WKCustomTableViewCell alloc] init];
//    custom.videoFrame = self.videoF;
//    return custom;
//}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        WKCustomTableViewCell *custom = [[WKCustomTableViewCell alloc] init];
            custom.videoFrame = self.videoF;
        custom.userInteractionEnabled = NO;
           return custom;
    }
        WKCommentCell *cell = [WKCommentCell cellWithTableView:tableView];
        cell.commentR = self.datas[indexPath.row];
        return cell;
   
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return self.videoF.cellHeight;
    }
    return 50;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 1) return @"最新评论";
    return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@end
